package com.pavlinic.codegen.experiments;

import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;

import java.io.PrintWriter;

import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.PackageDeclaration;
import org.junit.Test;

public class Experiment1 {
	private final class RenameAToBVisitor extends ASTVisitor {

		@Override
		public boolean visit(PackageDeclaration node) {
			node.setName(node.getAST().newName("newPackage"));
			return true;
		}
		
	}

	@Test public void experiment1() {
		final ASTParser astParser = ASTParser.newParser(AST.JLS3);
		astParser.setSource("package mypackage; public class A {}".toCharArray());
		final ASTNode astNode = astParser.createAST(null);
		astNode.accept(new RenameAToBVisitor());
		assertTrue(astNode.toString().contains("package newPackage;"));
	}
	
	@Test public void canWeMockPrintWriter() {
	  mock(PrintWriter.class);
	}
}
